import { Suspense, lazy, ComponentType } from 'react';
import { Spin } from 'antd';

export function lazyLoadComponent<T extends ComponentType<any>>(
  factory: () => Promise<{ default: T }>,
  fallback: React.ReactNode = <Spin />
) {
  const LazyComponent = lazy(factory);
  
  return function LazyLoadWrapper(props: React.ComponentProps<T>) {
    return (
      <Suspense fallback={fallback}>
        <LazyComponent {...props} />
      </Suspense>
    );
  };
}